
//
//  YHDrawview.m
//  LyhToolsTest
//
//  Created by LYH on 2019/2/26.
//  Copyright © 2019 LYH.com. All rights reserved.
//

#import "YHDrawview.h"

@implementation YHDrawview

- (void)drawRect:(CGRect)rect
{
   
        CGContextRef ref = UIGraphicsGetCurrentContext();//拿到当前准备好的花板
        
        CGContextBeginPath(ref); //开始绘画
    //第一种方式繁琐
//        //A
//        CGContextMoveToPoint(ref, kScreenWidth/2, kScreenWidth/2);//初始点
//
//        CGContextAddLineToPoint(ref, kScreenWidth/2+150, 300);//终点
//        //B
//        CGContextMoveToPoint(ref, kScreenWidth/2, kScreenWidth/2);//初始点
//
//        CGContextAddLineToPoint(ref, kScreenWidth/2-150, 300);//终点
//
//        //C
//        CGContextMoveToPoint(ref, kScreenWidth/2-150, 300);//初始点
//
//        CGContextAddLineToPoint(ref, kScreenWidth/2+150, 300);//终点
     //第二种 CGContextAddLines  定义好元素是CGPoint的数组后一行代码搞定
    CGPoint points[] = {{kScreenWidth/2, 0}, {kScreenWidth/2-75, 150}, {kScreenWidth/2+75, 150},{kScreenWidth/2, 0}};
      CGContextAddLines(ref, points, 4);
        
        CGFloat redcolor[4] = {1.0,0,0,1.0};
        CGContextSetStrokeColor(ref, redcolor);//画笔颜色
        CGContextSetLineWidth(ref, 5);
        CGContextStrokePath(ref);
    
}

@end
